#include "device.h"

void putchar(char c)
{
    SCI_writeCharBlockingNonFIFO(SCIB_BASE, c);
    while (!ScibRegs.LSR.bit.TEMT) // wait send finish
        ;
}

void puts(const char *str)
{
    while (*str)
    {
        putchar(*str);
        str++;
    }
    putchar('\n');
}

void set_exp_start(void)
{
    extern u32 _CORE0_IRAM_START;
    extern u32 _CORE1_IRAM_START;
    CpuSysRegs.CPU0EXPSTART.bit.EXPSTART = ((int)(&_CORE0_IRAM_START) >> 15) & 7;
    CpuSysRegs.CPU1EXPSTART.bit.EXPSTART = ((int)(&_CORE1_IRAM_START) >> 15) & 7;
}

void main_core0()
{
    set_exp_start();

    Interrupt_initVectorTable();

    Device_init();

    GPIO_MuxConfig(12, GPIO_12_SCIB_TX, GPIO_PIN_TYPE_STD, GPIO_QUAL_ASYNC);
    GPIO_MuxConfig(13, GPIO_13_SCIB_RX, GPIO_PIN_TYPE_STD, GPIO_QUAL_ASYNC);

    SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_SCIB);

    SCI_setConfig(SCIB_BASE, DEVICE_LSPCLK_FREQ, 921600,
        SCI_CONFIG_WLEN_8 | SCI_CONFIG_STOP_ONE | SCI_CONFIG_PAR_NONE);

    while (1)
    {
        DEVICE_DELAY_US(1000000);
        puts("hello world");
    }
}
